package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.SoulReportApi;
import com.tanhua.dubbo.mapper.SoulReportMapper;
import com.tanhua.dubbo.pojo.SoulReport;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService(version = "1.0.0")
public class SoulReportApiImpl implements SoulReportApi {

    @Autowired
    private SoulReportMapper soulReportMapper;


    @Override
    public SoulReport selectOne(String id) {

        QueryWrapper<SoulReport> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);

        return soulReportMapper.selectOne(queryWrapper);
    }

    @Override
    public SoulReport selectOne(Long id, Long paperid) {
        QueryWrapper<SoulReport> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userid", id);
        queryWrapper.eq("paperid", paperid);
        return soulReportMapper.selectOne(queryWrapper);
    }

    @Override
    public List<SoulReport> selectList(Long score, SoulReport soulReport) {

        QueryWrapper<SoulReport> queryListWrapper = new QueryWrapper<>();
        // ne, not equall
        queryListWrapper.between("score", score - 10, score + 10).
                ne("userid",soulReport.getUserid()).eq("paperid",soulReport.getPaperid());

        return soulReportMapper.selectList(queryListWrapper);
    }

    @Override
    public List<SoulReport> selectList(Long userId) {

        QueryWrapper<SoulReport> soulReportQueryWrapper = new QueryWrapper<>();
        soulReportQueryWrapper.eq("userid", userId);
        return soulReportMapper.selectList(soulReportQueryWrapper);
    }

    @Override
    public int insert(SoulReport soulReport) {
       return soulReportMapper.insert(soulReport);
    }

    @Override
    public void update(SoulReport soulReport) {
        QueryWrapper<SoulReport> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userid", soulReport.getUserid()).eq("paperid", soulReport.getPaperid());
        soulReportMapper.update(soulReport,queryWrapper);
    }
}
